
function UrlSearch() 
{
   var name,value; 
   var str=location.href; //取得整个地址栏
   var num=str.indexOf("?") 
   str=str.substr(num+1); //取得所有参数   stringvar.substr(start [, length ]
   var arr=str.split("&"); //各个参数放到数组里
   for(var i=0;i < arr.length;i++){ 
    num=arr[i].indexOf("="); 
    if(num>0){ 
     name=arr[i].substring(0,num);
     value=arr[i].substr(num+1);
     this[name]=value;
     } 
    } 
} 
var Request=new UrlSearch(); //实例化
//alert(Request.billCode);
var billCode = Request.billCode;
var ladingBillCode = Request.ladingBillCode;
var shipperName = Request.shipperName;



var feeStore = Ext.create('Ext.data.Store', {
	fields: ['id', 'name'],
	data : [
		{"id":"0", "name":"业务板块"},
		{"id":"1", "name":"船代板块"},
//		{"id":"0", "name":"船务板块"}
	]
});
var bizhongStore = Ext.create('Ext.data.Store', {
	fields: ['BIZHONG'],
	data : [
		{"BIZHONG":"RMB"},
		{"BIZHONG":"USD"},
	]
});
var store = Ext.create('Ext.data.Store', {
    fields: ["ID",
             "SETTLEMENT_UNIT",
             "COST_NAME",
             "CURRENCY",
             "CONTAINER_TYPE",
             "TAX_PRICE",
             "CONTAINER_NUM",
             "AMOUNT",
             "EXCHANGE_RATE",
             "EQUIVALENT_RMB",
             "REMARK",
             "COST_TYPE",
             "COST_PLATE",
             "INPUTER"],
    pageSize: 15,  //页容量5条数据
    //是否在服务端排序 （true的话，在客户端就不能排序）
    remoteSort: false,
    remoteFilter: true,
    proxy: {
        type: 'ajax',
        url: '../consignHandle/listByBillCode?billCode='+billCode+"&ladingBillCode="+ladingBillCode,
        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
            type: 'json', //返回数据类型为json格式
            root: 'result.list',  //数据
            totalProperty: 'result.total' //数据总条数
        }
    },
    sorters: [{
        property: 'ordeId',
        direction: 'desc'
    }],
//    autoLoad: true
   
});
store.load({
    callback :function(r,options,success){  
        if(success){  
        	allAmount();
        }  
    }  
    });
var FeeNamestore = Ext.create('Ext.data.Store', {
    fields: ["FEE_NAME","ID"],
    pageSize: 15,  //页容量5条数据
    //是否在服务端排序 （true的话，在客户端就不能排序）
    remoteSort: false,
    remoteFilter: true,
    proxy: {
        type: 'ajax',
        url: '../consignHandle/findFeeNameInfo',
        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
            type: 'json', //返回数据类型为json格式
            root: 'root',  //数据
//            totalProperty: 'result.total' //数据总条数
        }
    },
    sorters: [{
        property: 'ordeId',
        direction: 'desc'
    }],
    autoLoad: true
});

var settlementstore = Ext.create('Ext.data.Store', {
    fields: ["ENTITIES_FULLNAME","IS_INNER_SETTLEMENT"],
    pageSize: 15,  //页容量5条数据
    //是否在服务端排序 （true的话，在客户端就不能排序）
    remoteSort: false,
    remoteFilter: true,
    proxy: {
        type: 'ajax',
        url: '../consignHandle/findSettlement',
        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
            type: 'json', //返回数据类型为json格式
            root: 'settlement',  //数据
//            totalProperty: 'result.total' //数据总条数
        }
    },
    sorters: [{
        property: 'ordeId',
        direction: 'desc'
    }],
    autoLoad: true
});
var boxTypeStore = Ext.create('Ext.data.Store', {
    fields: ["BOX_TYPE_NAME"],
    pageSize: 15,  //页容量5条数据
    //是否在服务端排序 （true的话，在客户端就不能排序）
    remoteSort: false,
    remoteFilter: true,
    proxy: {
        type: 'ajax',
        url: '../consignHandle/findboxType',
        reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
            type: 'json', //返回数据类型为json格式
            root: 'boxType',  //数据
//            totalProperty: 'result.total' //数据总条数
        }
    },
    sorters: [{
        property: 'ordeId',
        direction: 'desc'
    }],
    autoLoad: true
});


var grid = new Ext.grid.GridPanel({
    //renderTo: "output",
//	renderTo:'output',
    store: store,
    //height: document.documentElement.clientHeight,
    height:150,
    stripeRows:true,
    columnLines: true,
    selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"}),
    columns: [
         {text: 'ID', dataIndex: 'ID', id:'ID',align: 'left', hidden:true,maxWidth: 100 },
         {text: '结算单位', dataIndex: 'SETTLEMENT_UNIT', align: 'left', maxWidth: 100 },
        {text: '费用名称', dataIndex: 'COST_NAME', maxWidth: 200 },
        {text: '币种', dataIndex: 'CURRENCY', maxWidth: 80},
        {text: '箱型', dataIndex: 'CONTAINER_TYPE', maxWidth: 80},
        {text: '单价', dataIndex: 'TAX_PRICE', maxWidth: 80, render:convertDate},
        {text: '数量', dataIndex: 'CONTAINER_NUM', align: 'left', minWidth: 80},
        {text: '应付金额', dataIndex: 'AMOUNT', maxWidth: 80},
        {text: '比率', dataIndex: 'EXCHANGE_RATE', maxWidth: 80},
        {text: '折合人民币', dataIndex: 'EQUIVALENT_RMB', maxWidth: 80},
        {text: '备注', dataIndex: 'REMARK', maxWidth: 80 , render:convertDate},
        {text: '对账', dataIndex: 'forwarderCustomerService', maxWidth: 80},
        {text: '审核', dataIndex: 'transportClause', maxWidth: 80},
        {text: '开票', dataIndex: 'boxTypeConfirm', maxWidth: 80},
        {text: '收款', dataIndex: 'chineseName', maxWidth: 80},
        {text: '费用类型', dataIndex: 'COST_TYPE', maxWidth: 80},
        {text: '费用板块', dataIndex: 'COST_PLATE', maxWidth: 80},
        {text: '录入人', dataIndex: 'INPUTER', maxWidth: 80}
    ],
//    bbar: [{
//        xtype: 'pagingtoolbar',
//        store: store,
//        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
//        emptyMsg: "没有数据",
//        beforePageText: "当前页",
//        afterPageText: "共{0}页",
//        displayInfo: true
//    }],
//    listeners: {
//        'cellclick': function (grid,row) {
//        			alert("1");
//        			grid.item;
//        }
//    }
});
function convertDate(val) {
    return Ext.util.Format.date(new Date(val), 'Y-m-d');
}

var tradeTypeStore = Ext.create('Ext.data.Store', {
    fields: ['id', 'name'],
    data : [
        {"id":"", "name":"全部"},
        {"id":"AK", "name":"内贸"},
        {"id":"AZ", "name":"外贸"}
    ]
});

var c1 = Ext.create('Ext.container.Container', {
    layout: 'column',
    defaults: { labelAlign: 'left', labelWidth: 60 },
    items: [
        {xtype: 'combobox',  name: 'startDate5', id: 'startDate5',columnWidth:  1/5,padding: '5px', fieldLabel: '费用板块',editable: false,displayField: 'name',store:feeStore},
        {xtype: 'combobox', name: 'startDate1',id: 'startDate1',columnWidth: 1/5,padding: '5px',fieldLabel: '费用名称',store:FeeNamestore,editable: false,displayField:'FEE_NAME'},
        {xtype: 'combobox', name: 'startDate2',id: 'startDate2', columnWidth:  1/5,padding: '5px', fieldLabel: '币种',store:bizhongStore,editable: false,displayField: 'BIZHONG'},
        {xtype: 'combobox', name: 'startDate3',id: 'startDate3',columnWidth: 1/5,padding: '5px',fieldLabel: '结算单位',store:settlementstore,editable: false,displayField: 'ENTITIES_FULLNAME',valueField:'IS_INNER_SETTLEMENT'},
        {xtype: 'combobox',  name: 'startDate11',id: 'startDate11',value:'',editable: false,displayField: 'BOX_TYPE_NAME', queryMode: 'local',store:boxTypeStore,  columnWidth:  1/5,padding: '5px', fieldLabel: '箱型'}
    ]
});
var c2 = Ext.create('Ext.container.Container', {
    layout: 'column',
	defaults: { labelAlign: 'left', labelWidth: 60 },
    items: [
            {xtype: 'textfield', name: 'startDate99', id: 'startDate99',hidden:true,padding: '5px', fieldLabel: 'ID'},
        {xtype: 'textfield', name: 'startDate6', id: 'startDate6',columnWidth: 1/5,padding: '5px', fieldLabel: '单价'},
        {xtype: 'textfield', name: 'startDate7',id: 'startDate7',columnWidth:  1/5,padding: '5px',fieldLabel: '数量'},
        {xtype: 'textfield', name: 'startDate9',id: 'startDate9',columnWidth:  1/5,padding: '5px',fieldLabel: '比率'},
        {xtype: 'textfield', name: 'startDate4',id: 'startDate4',columnWidth:  1/5,padding: '5px',fieldLabel: '备注'},
    ]
});
var cc3 = Ext.create('Ext.container.Container', {
    layout: 'column',
	defaults: { labelAlign: 'left', labelWidth: 60 },
    items: [
        {xtype: 'textfield', name: 'startDate62', id: 'startDate62',columnWidth: 1/5,padding: '5px', labelWidth: 90,fieldLabel: '合计人民币'},
        {xtype: 'textfield', name: 'startDate72',id: 'startDate72',columnWidth:  1/5,padding: '5px',labelWidth: 60,fieldLabel: '合计美元'},
        {xtype: 'textfield', name: 'startDate92',id: 'startDate92',columnWidth:  1/5,padding: '5px',labelWidth: 100,fieldLabel: '合计折合人民币'},
//        {xtype: 'textfield', name: 'startDate4',id: 'startDate4',columnWidth:  1/5,padding: '5px',fieldLabel: '备注'},
    ]
});
var bs = Ext.create('Ext.container.Container', {
    layout: 'form',
    items: [
//        {layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,   padding: '10px'},
			{layout : 'column',baseCls : 'my-panel-no-border',columnWidth: 1/5,  padding: '10px',  items: [
            {xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "增加应收费用",handler:function(){
            	var COST_PLATE = Ext.getCmp('startDate5').getValue();
	      		var COST_NAME = Ext.getCmp('startDate1').getValue();
	      		var CURRENCY = Ext.getCmp('startDate2').getValue();
	      		var SETTLEMENT_UNIT = Ext.getCmp('startDate3').getRawValue();
	      		var CONTAINER_TYPE = Ext.getCmp('startDate11').getValue();
	      		var TAX_PRICE = Ext.getCmp('startDate6').getValue();
	      		var CONTAINER_NUM = Ext.getCmp('startDate7').getValue();
	      		var EXCHANGE_RATE = Ext.getCmp('startDate9').getValue();
	      		var REMARK = Ext.getCmp('startDate4').getValue();
	      		var IS_INNER_SETTLEMENT = Ext.getCmp('startDate3').getValue();
	      		var BILL_CODE= billCode;
	      		var LADING_BILL_CODE= ladingBillCode;
	      		if((COST_PLATE==null || COST_PLATE=="")&&(COST_NAME==null || COST_NAME=="")&&(CURRENCY==null || CURRENCY=="")&&(SETTLEMENT_UNIT==null || SETTLEMENT_UNIT=="")&&(CONTAINER_TYPE==null || CONTAINER_TYPE=="")&&(TAX_PRICE==null||TAX_PRICE=="")&&(CONTAINER_NUM==null||CONTAINER_NUM=="")&&(EXCHANGE_RATE==null||EXCHANGE_RATE=="")&&(REMARK==null||REMARK=="")){
	      			Ext.MessageBox.alert("提示","请填写数据");
	      			return false;
	      		}
	      		 Ext.Ajax.request({
	       			 url: '../consignHandle/saveFeeInfo',
	        			 params:{COST_PLATE:COST_PLATE,COST_NAME:COST_NAME,CURRENCY:CURRENCY,
	        				 SETTLEMENT_UNIT:SETTLEMENT_UNIT,CONTAINER_TYPE:CONTAINER_TYPE,
	        				 TAX_PRICE:TAX_PRICE,CONTAINER_NUM:CONTAINER_NUM,EXCHANGE_RATE:EXCHANGE_RATE,REMARK:REMARK,
	        				 BILL_CODE:BILL_CODE,LADING_BILL_CODE:LADING_BILL_CODE,IS_INNER_SETTLEMENT:IS_INNER_SETTLEMENT
	        			 },
	        			 method: 'POST',
	        			success: function () {
	                       Ext.MessageBox.alert("保存成功","保存成功");
//		                       var grid = Ext.getCmp('grid');
							Ext.getCmp("startDate1").setValue(null); 
							Ext.getCmp("startDate2").setValue(null); 
							Ext.getCmp("startDate3").setValue(null); 
							Ext.getCmp("startDate4").setValue(null); 
							Ext.getCmp("startDate5").setValue(null); 
							Ext.getCmp("startDate6").setValue(null); 
							Ext.getCmp("startDate7").setValue(null);  
							Ext.getCmp("startDate9").setValue(null); 
	   					 grid.store.reload();
	   					 gridOut.store.reload();
	                   },
	                   failure : function(response, request) {
	                	   Ext.MessageBox.alert('错误提示', '请求' + request.url + '出错');
	                	   }
	        		 });
            } },
            {xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "删除应收费用",handler:function(){
	     		var records = grid.getSelectionModel().getSelection();
       			if(records.length==0){
       				Ext.Msg.alert("提示","请选中需要删除的记录");return;
       			}
       			
       			var arr = [];
       			Ext.each(records,function(item){
       				obj = {
       						ID:item.data.ID
       				};
       				arr.push(obj);
       			});
       			var array = JSON.stringify(arr);
       			Ext.Msg.confirm("提示","确定删除数据?",function(btn){
	       				
	       					Ext.Ajax.request({
	       						url:'../consignHandle/deleteFee',
	       						params:{
	       							array:array
	       						},
	       						timeout:5000,
	       						success:function(response){
	       							store.load();
	       							Ext.Msg.alert("成功","删除成功!");
	       						},
	       						failure:function(response){
	       							Ext.Msg.alert("错误","请求异常!");
	       						}
	       					});
	       				
	       			});
     	} },
     	 {xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "修改应收费用",handler:function(){
     		var records = grid.getSelectionModel().getSelection();
   			if(records.length==0){
   				Ext.Msg.alert("提示","请选中需要修改的记录");return;
   			}
   			if(records.length>1){
   				Ext.Msg.alert("提示","只能选中一条记录修改");return;
   			}
   			  Ext.getCmp('startDate99').setValue(records[0].data.ID);
   			
   	     	Ext.getCmp('startDate5').setValue(records[0].data.COST_PLATE);
      		Ext.getCmp('startDate1').setValue(records[0].data.COST_NAME);
      		Ext.getCmp('startDate2').setValue(records[0].data.CURRENCY);
      		Ext.getCmp('startDate3').setValue(records[0].data.SETTLEMENT_UNIT);
      		Ext.getCmp('startDate11').setValue(records[0].data.CONTAINER_TYPE);
      		Ext.getCmp('startDate6').setValue(records[0].data.TAX_PRICE);
      		Ext.getCmp('startDate7').setValue(records[0].data.CONTAINER_NUM);
      		Ext.getCmp('startDate9').setValue(records[0].data.EXCHANGE_RATE);
      		Ext.getCmp('startDate4').setValue(records[0].data.REMARK);
//      		var BILL_CODE= billCode;
//      		var LADING_BILL_CODE= ladingBillCode;
        }
   			
   			
   			
     	 },
     	{xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "保存修改应收费用",handler:function(){
     		var ID = Ext.getCmp('startDate99').getValue();
     		var COST_PLATE = Ext.getCmp('startDate5').getValue();
      		var COST_NAME = Ext.getCmp('startDate1').getValue();
      		var CURRENCY = Ext.getCmp('startDate2').getValue();
      		var SETTLEMENT_UNIT = Ext.getCmp('startDate3').getValue();
      		var CONTAINER_TYPE = Ext.getCmp('startDate11').getValue();
      		var TAX_PRICE = Ext.getCmp('startDate6').getValue();
      		var CONTAINER_NUM = Ext.getCmp('startDate7').getValue();
      		var EXCHANGE_RATE = Ext.getCmp('startDate9').getValue();
      		var REMARK = Ext.getCmp('startDate4').getValue();
      		var BILL_CODE= billCode;
      		var LADING_BILL_CODE= ladingBillCode;
      		 Ext.Ajax.request({
       			 url: '../consignHandle/updateFeeInfo',
        			 params:{ID:ID,COST_PLATE:COST_PLATE,COST_NAME:COST_NAME,CURRENCY:CURRENCY,
        				 SETTLEMENT_UNIT:SETTLEMENT_UNIT,CONTAINER_TYPE:CONTAINER_TYPE,
        				 TAX_PRICE:TAX_PRICE,CONTAINER_NUM:CONTAINER_NUM,EXCHANGE_RATE:EXCHANGE_RATE,REMARK:REMARK,
        				 BILL_CODE:BILL_CODE,LADING_BILL_CODE:LADING_BILL_CODE
        			 },
        			 method: 'POST',
        			success: function () {
                       Ext.MessageBox.alert("保存成功","保存成功");
//	                       var grid = Ext.getCmp('grid');
						Ext.getCmp("startDate1").setValue(null); 
						Ext.getCmp("startDate2").setValue(null); 
						Ext.getCmp("startDate3").setValue(null); 
						Ext.getCmp("startDate4").setValue(null); 
						Ext.getCmp("startDate5").setValue(null); 
						Ext.getCmp("startDate6").setValue(null); 
						Ext.getCmp("startDate7").setValue(null);  
						Ext.getCmp("startDate9").setValue(null); 
   					 grid.store.reload();
                   },
                   failure : function(response, request) {
                	   Ext.MessageBox.alert('错误提示', '请求' + request.url + '出错');
                	   }
        		 });
     	}},
     	{xtype: "button",minWidth:70,icon:'../plugins/websocketInstantMsg/ext4/shared/icons/fam/add.png', text: "费用完成",handler:function(){
      		 Ext.Ajax.request({
       			 url: '../consignHandle/editState',
        			 params:{
        				 BILL_CODE:billCode,
        				 IS_FEE_FINISH:"1"
        			 },
        			 method: 'POST',
        			success: function () {
                       Ext.MessageBox.alert("保存成功","保存成功");
//	                       var grid = Ext.getCmp('grid');
						Ext.getCmp("startDate1").setValue(null); 
						Ext.getCmp("startDate2").setValue(null); 
						Ext.getCmp("startDate3").setValue(null); 
						Ext.getCmp("startDate4").setValue(null); 
						Ext.getCmp("startDate5").setValue(null); 
						Ext.getCmp("startDate6").setValue(null); 
						Ext.getCmp("startDate7").setValue(null);  
						Ext.getCmp("startDate9").setValue(null); 
   					 grid.store.reload();
                   },
                   failure : function(response, request) {
                	   Ext.MessageBox.alert('错误提示', '请求' + request.url + '出错');
                	   }
        		 });
     	}}
        ]},
//        {layout : 'column',baseCls : 'my-panel-no-border', columnWidth: 2/5,  padding: '10px'}
    ]
});
var returnInfo =new Ext.Button({
	text: '返回上一页',
	handler:function(){
		javascript:history.back(-1);
 	}
});
var selForm = Ext.create('Ext.form.Panel', {
    title:'托单应收费用',
    name: 'selForm',
    //collapsed :true,
//    renderTo:'selForm',
    height:140,
    collapsible:true,
    bodyStyle: {
        padding: '5px',
        border: 1
    },
    fieldDefaults: {
        labelAlign: 'left'
    },
    items: [c1, c2,bs],
    tools:[{ id:"help" }]
});
var selForm2 = Ext.create('Ext.form.Panel', {
//    title:'托单应收费用',
    name: 'selForm2',
    //collapsed :true,
//    renderTo:'selForm',
    height:50,
//    collapsible:true,
//    bodyStyle: {
//        padding: '5px',
//        border: 1
//    },
//    fieldDefaults: {
//        labelAlign: 'left'
//    },
    items: [cc3],
//    tools:[{ id:"help" }]
   
});
//allAmount();
function allAmount(){
	var aa= grid.getStore()
	var RMB = 0;
	var USD = 0
	var zehe = 0
	for(var i=0;i<aa.getCount();i++)
	{
		if(grid.getStore().data.items[i].data.CURRENCY=='RMB'){
			RMB+=parseInt(grid.getStore().data.items[i].data.TAX_PRICE)*parseInt(grid.getStore().data.items[i].data.CONTAINER_NUM);
		}else if(grid.getStore().data.items[i].data.CURRENCY=='USD'){
			USD+=parseInt(grid.getStore().data.items[i].data.TAX_PRICE)*parseInt(grid.getStore().data.items[i].data.CONTAINER_NUM);
		}
		zehe+=parseInt(grid.getStore().data.items[i].data.EQUIVALENT_RMB);
			
//	   comValue+=parseInt(grid.getStore().data.items[i].data.TAX_PRICE);
	   
	  
	}
	
	Ext.getCmp("startDate62").setValue(RMB); 
	Ext.getCmp("startDate72").setValue(USD); 
	Ext.getCmp("startDate92").setValue(zehe); 
//	 alert(RMB);
//	   alert(USD);
}